<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程设置</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
	
<body class="iframeBody">
<div class="Wrapper">
    <table class="layout2col1">
        <tbody>
            <tr>
                <td valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_3"></i>组织架构</span>
                        </div>
                        <div class="sqPanel_body" style="min-height: 300px;">
                            <div class="btnsBox">&nbsp;</div>
                            <div class="nanoWrap" style="height: 360px;">
                                <div class="nano"><div class="nano-content">
                                    <ul id="flow_setting_tree_id">
                                    </ul>
                                </div></div>
                            </div>
                        </div>
                    </div>
                </td>
                <td width="70%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <form id="flow_setting_search_form_id" class="titSearchBar">
                                <div class="fieldset1 clearFix">
                                    <div class="fieldBox">
                                        <div class="label">流程名称</div>
                                        <div class="field">
                                             <input name="flowNm" id="flowNm" type="text" class="ui-textbox" value="">
                                        </div>
                                    </div>
                                    <span id="flow_setting_search_btn_id" class="sq-search-button"></i>查询</span>
                                </div>
                            </form>
                        </div>
                        <div class="sqPanel_body">
                            <div class="FBL5">
                                <span id="sp_flow_set_add_id" class="sq-button sq-button-round">新增</span>
                                <span id="sp_flow_set_remove_id" class="sq-button sq-button-round">移除</span>
                            </div>
                            <div id="flow_setting_grid_id" class="sq-grid"></div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>

<script type="text/javascript">

var tree,settingGrid;
$(function () {
	initData();
	initEvent();
});

//初始化数据
function initData(){
	initTree();
	initSearchForm();
}

//初始化事件
function initEvent(){
	searchBtnEvent();
	initBtnEvent();
}

//新增按钮事件
function initBtnEvent(){
	//新增
    $("#sp_flow_set_add_id").click(function(event) {
        if (!tree.getSelected()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_ORG,SQ_type: "warning"});
            return;
        };
        $.ligerDialog.SQopen({
            width: 850,
            height:550,
            top: 25,
            title : '关系',
            parms:{orgCd:currentOrgCd},
            url:'<%=path%>/flow/flow/toFlowSettingAddPage.do?orgCd='+currentOrgCd
        });
    });
    
    //删除
    $("#sp_flow_set_remove_id").click(function(event) {
    	  var _grid = settingGrid.getSelectedRows();
          if(_grid.length == 0){
	  			top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
	  			return;
  		  }
          
        var _ids = [];
  		for ( var index in _grid) {
  			_ids.push(_grid[index].id);
  		}
        
  		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var _url = '<%=path%>/system/sysflowmanageorgr/removeByIds.do';
			AjaxUtils.ajaxPost(_url, {ids:JSON.stringify(_ids)}, function(msg){
				if(msg.success == 1){
					 reloadGrid();
				 }else{
					 UIUtils.alertError(msg.info);
				 }
			},true);
			
  		});
  		
    });
}


function searchBtnEvent(){
	//查询按钮事件
    $("#flow_setting_search_btn_id").click(function(event) {
        if (!tree.getSelected()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_ORG,SQ_type: "warning"});
            return;
        };
        reloadGrid();
    });
}

//初始化查询表单
function initSearchForm(){
    $("#flow_setting_search_form_id").ligerForm();
}

//初始化列表数据
var currentOrgCd;
function initTree(){
    tree = $("#flow_setting_tree_id").ligerTree({
    	url: '<%=path%>/system/sysOrg/initList.do',
        ajaxType: 'get',
        checkbox: false,
        // single: true,
        parentIcon: "SqFolder",
        childIcon: "SqLeaf",
        needCancel:false,
        isExpand: true,
        isLeaf: function (data) {
            if (!data) return false;
            if (data.hasChildren) {return false} else if(data.children){return false} else {return true};
        },
        delay: function(e)
        {
        },
        onAfterAppend: function (parentNode, newdata) {
            setNanoScroller();
        },
        onExpand: function (node) {
            setNanoScroller();
        },
        onCollapse: function (node) {
            setNanoScroller();
        },
        onSelect: function (node) {
            currentOrgCd = node.data.orgCd;
            reloadGrid();
        },
        onCancelselect: function (data,target) {
            if (settingGrid) {settingGrid.grid.hide()}
        },
        onSuccess: function (data) {
            setNanoScroller();
            tree.selectNode(data[0]);
        }
    });
}

//从新加载Grid
function reloadGrid(){
    var parms={
        "orgCd":currentOrgCd
    };
    if (settingGrid) {
    	var form=liger.get("flow_setting_search_form_id");
        var data = form.getData();
        //alert(JSON.stringify(data));
        for (name in data) {
        	settingGrid.setParm(name, data[name])
        };
        settingGrid.setParm("orgCd", parms.orgCd);
        settingGrid.reload();
    }else{
        initGrid (parms)
    };
}

//初始化Grid
function initGrid (parms) {
    settingGrid = $("#flow_setting_grid_id").ligerGrid({
    	url: '<%=path%>/system/sysflowmanageorgr/initList.do',
        parms: parms,
        root:'rows',
        record:'total',
        method : 'get',
        fixedCellHeight: false,
        checkbox: true,
        rownumbers:true,
        selectRowButtonOnly: true,
        // isSingleCheck: true,
        //frozenCheckbox: false,//如果没有数据会隐藏表头
        //WallowHideColumn: false,
        columns: [{
        	display: '流程名称',
            name: 'flowNm',
            minWidth: 120
            
        }, {
        	display: '启用版本名称',
            name: 'useVersNm',
            minWidth: 120
        }, {
        	display: '流程业务分类',
            name: 'modelTypNm',
            minWidth: 120
            
        }, {
        	display: '流程状态',
            name: 'rlNm',
            minWidth: 120,
            render: function (rowdata, rowindex, value) {
            	if(rowdata.isValid == 1){
            		return LogUtils.LOG_CMM_GRID_BTN_ENABLE;
            	}else if(rowdata.isValid == 0){
            		return LogUtils.LOG_CMM_GRID_BTN_DISABLE;
            	}
            }
        }],
        //width: '100%',
        height:'100%',
        heightDiff:-2,
        isScroll: false,
        hideLoadButton : true,
        usePagerOnLessPagesize: false,
        onAfterShowData: function() {
            //SetIframe_height();
        }
    });
    //settingGrid.setHeight(100);
}

function setNanoScroller () {
    $(".nanoWrap .nano").nanoScroller({
        preventPageScrolling: true
    });
}

</script>

</body>
</html>
